using System;
using System.Reflection;
using Rhino.Mocks;

namespace wMobinium.core.test
{
    [NUnit.Framework.TestFixture]
    public class TestClassInfoTest
    {
        private MockRepository mocks;
        private Type typeMock;

        [NUnit.Framework.SetUp]
        public void SetUp()
        {
            mocks = new MockRepository();
            typeMock = mocks.CreateMock<Type>();
        }

        [NUnit.Framework.Test]
        public void EnsureThatPropertiesWorks()
        {
            string expectedTypeName = "MyType";
            string expectedFullName = "MyAssembly.MyType";

            string expectedMethodName1 = "2 - Method1";
            string expectedMethodName2 = "1 - Method1";

            MethodInfo[] methodsInfos =
                new MethodInfo[] {mocks.CreateMock<MethodInfo>(), mocks.CreateMock<MethodInfo>()};

            Expect.Call(typeMock.Name).IgnoreArguments().Return(expectedTypeName);
            Expect.Call(typeMock.FullName).IgnoreArguments().Return(expectedFullName);

            Expect.Call(methodsInfos[0].Name).IgnoreArguments().Repeat.Any().Return(expectedMethodName1);
            Expect.Call(methodsInfos[1].Name).IgnoreArguments().Repeat.Any().Return(expectedMethodName2);
            Expect.Call(methodsInfos[0].IsDefined(null, true)).IgnoreArguments().Repeat.Any().Return(true);
            Expect.Call(methodsInfos[1].IsDefined(null, true)).IgnoreArguments().Repeat.Any().Return(true);

            Expect.Call(typeMock.GetMethods()).IgnoreArguments().Repeat.Any().Return(methodsInfos);

            mocks.ReplayAll();

            TestClassInfo testClassInfo = new TestClassInfo(typeMock);

            Assert.AreEqual(expectedTypeName, testClassInfo.Name);
            Assert.AreEqual(expectedFullName, testClassInfo.FullName);
            Assert.AreEqual(2, testClassInfo.TestMethodInfos.Count);
            Assert.AreEqual(expectedMethodName2, testClassInfo.TestMethodInfos[0].Name);
            Assert.AreEqual(expectedMethodName1, testClassInfo.TestMethodInfos[1].Name);

            mocks.VerifyAll();
        }
    }
}